package com.ruoyi.project.g6.controller;

import com.ruoyi.project.g6.api.Api;
import com.ruoyi.project.g6.entity.Auth;
import com.ruoyi.project.g6.entity.ChipPrefix;
import com.ruoyi.project.g6.entity.TboxModelAuthority;
import com.ruoyi.project.g6.entity.common.G6Record;
import com.ruoyi.project.g6.entity.common.ResponseResult;
import com.ruoyi.project.g6.entity.vo.*;
import com.ruoyi.project.g6.service.IG6ChipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("dev")
@Transactional
public class G6ApiDevController {

    @Autowired
    private IG6ChipService ig6ChipService;

    @Autowired
    private Api api;

    /**
     * 4.1 平台登录
     *
     * @param auth 包含用户名,密码的实体
     * @return token
     */
    @PostMapping("/api/v10/login")
    public ResponseResult login(@RequestBody Auth auth) {
        return api.login(auth);
    }

    /**
     * 4.2 发动机型号备案
     *
     * @param vehicleEngine 发动机引擎的数据json
     * @return
     */
    @PostMapping("/api/v10/insertVehicleEngine")
    public ResponseResult insertVehicleEngine(@RequestBody VehicleEngineVO vehicleEngine) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("ok");
        responseResult.setType(ResponseResult.SUCCESS);

        G6Record g6Record = G6Record.newInstance(vehicleEngine,responseResult);

        ig6ChipService.insertG6Record(g6Record);
        return responseResult;
    }

    /**
     * 4.3 车辆型号备案
     *
     * @param vehicleType 车辆型号数据json
     * @return
     */
    @PostMapping("/api/v10/insertVehicleType")
    public ResponseResult insertVehicleType(@RequestBody VehicleTypeVO vehicleType) {
        //return api.insertVehicleType(vehicleType);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("ok");
        responseResult.setType(ResponseResult.SUCCESS);

        G6Record g6Record = G6Record.newInstance(vehicleType,responseResult);

        ig6ChipService.insertG6Record(g6Record);
        return responseResult;
    }

    /**
     * 4.4 芯片型号备案
     * 2019年12月16日 10:10:16 前端通
     * @param chipModel 芯片型号实体
     * @return
     */
    @PostMapping("/api/v10/insertChipModel")
    public ResponseResult insertChipModel(@RequestBody ChipModelVO chipModel) {

        // return api.insertChipModel(chipModel);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("ok");
        responseResult.setType(ResponseResult.SUCCESS);

        G6Record g6Record = G6Record.newInstance(chipModel,responseResult);
        ig6ChipService.insertG6Record(g6Record);
        return responseResult;
    }

    /**
     * 4.5 芯片型号备案结果查询
     *
     * @param commonVo 申请芯片型号备案时获得的申请序号+令牌
     * @return
     */
    @PostMapping("/api/v10/insertChipModelResult")
    public ResponseResult insertChipModelResult(@RequestBody CommonVo commonVo) {
        //return api.insertChipModelResult(commonVo);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("ok");
        responseResult.setType(ResponseResult.SUCCESS);
        return responseResult;
    }


    /**
     * 4.6 已备案芯片型号查询
     * <p>
     * chipModel 芯片型号参数实体，为空时返回本企业所有已备案成功芯片型号
     *           空指"" 或 null
     * token     令牌
     *
     * @return
     */
    @PostMapping("/api/v10/getChipModel")
    public ResponseResult getChipModel(@RequestBody GetChipModelVo getChipModelVo) {
        return api.getChipModel(getChipModelVo);
    }

    /**
     * 4.7 芯片型号标识符申请
     *
     * @param chipPrefix 这里面包含令牌字段,如果为空的话会拿第二个参数进行设置
     * @return
     */
    @PostMapping("/api/v10/getChipPrefix")
    public ResponseResult getChipPrefix(@RequestBody ChipPrefix chipPrefix) {
        //return api.getChipPrefix(chipPrefix, null);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("ok");
        responseResult.setType(ResponseResult.SUCCESS);

        G6Record g6Record = G6Record.newInstance(chipPrefix,responseResult);
        ig6ChipService.insertG6Record(g6Record);
        return responseResult;
    }

    /**
     * 4.8 芯片型号标识符申请结果查询
     *
     * @param commonVo 申请芯片型号备案时获得的申请序号+令牌
     * @return
     */
    @PostMapping("/api/v10/getChipPrefixResult")
    public ResponseResult getChipPrefixResult(@RequestBody CommonVo commonVo) {
        return api.getChipPrefixResult(commonVo);

    }

    /**
     * 4.9 车载终端型号备案
     * 2019年12月16日 10:19:23 通
     */
    @PostMapping("/api/v10/insertTbox")
    public ResponseResult insertTbox(@RequestBody TboxVO tbox) {
        // return api.insertTbox(tbox);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("ok");
        responseResult.setType(ResponseResult.SUCCESS);
        return responseResult;
    }

    /**
     * 4.10 车载终端型号备案结果查询
     *
     * @param commonVo 申请芯片型号备案时获得的申请序号+令牌
     * @return
     */
    @PostMapping("/api/v10/insertTboxModelResult")
    public ResponseResult insertTboxModelResult(@RequestBody CommonVo commonVo) {
        return api.insertTboxModelResult(commonVo);
    }

    /**
     * 4.11 已备案车载终端型号查询
     *
     * @return
     */
    @PostMapping("/api/v10/getTboxModel")
    public ResponseResult getTboxModel(@RequestBody GetTboxModelVo getTboxModelVo) {
        return api.getTboxModel(getTboxModelVo);

    }

    /**
     * 4.12 车载终端型号授权备案
     *
     * @param tboxModelAuthority 车组终端型号json实体
     * @return
     */
    @PostMapping("/api/v10/insertTboxModelAuthority")
    public ResponseResult insertTboxModelAuthority(@RequestBody TboxModelAuthority tboxModelAuthority) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("ok");
        responseResult.setType(ResponseResult.SUCCESS);

        G6Record g6Record = G6Record.newInstance(tboxModelAuthority,responseResult);
        ig6ChipService.insertG6Record(g6Record);
        return responseResult;
        //return api.insertTboxModelAuthority(tboxModelAuthority);

    }

    /**
     * 4.13 车载终端型号授权备案结果查询
     *
     * @param commonVo 申请芯片型号备案时获得的申请序号+令牌
     * @return
     */
    @PostMapping("/api/v10/insertTboxModelAuthorityResult")
    public ResponseResult insertTboxModelAuthorityResult(@RequestBody CommonVo commonVo) {
        return api.insertTboxModelAuthorityResult(commonVo);

    }

    /**
     * 4.14 更换终端信息备案
     *
     * @return
     */
    @PostMapping("/api/v10/changeTbox")
    public ResponseResult changeTbox(@RequestBody TboxChangeVO tboxChange) {
        return api.changeTbox(tboxChange);

    }

    /**
     * 4.15 更换终端信息备案结果查询
     *
     * @param commonVo 申请芯片型号备案时获得的申请序号+令牌
     * @return
     */
    @PostMapping("/api/v10/changeTboxResult")
    public ResponseResult changeTboxResult(@RequestBody CommonVo commonVo) {
        return api.changeTboxResult(commonVo);
    }

    /**
     * 4.16 车辆信息备案申请
     * 重型车远程排放服务与管理国家平台>5.4 车辆信息备案
     * 对于非必填的处理,非必填项应填写空字符串“”
     *
     * @param vehicle 车辆信息
     * @return
     */
    @PostMapping("/api/v10/insertVehicle")
    public ResponseResult insertVehicle(@RequestBody VehicleVO vehicle) {
        return api.insertVehicle(vehicle);
    }

    /**
     * 4.17 车辆状态查询
     *
     * @return
     */
    @PostMapping("/api/v10/vehicleStatus")
    public ResponseResult vehicleStatus(@RequestBody GetVehicleStatusVO getVehicleStatusVO) {
        return api.vehicleStatus(getVehicleStatusVO);
    }

}
